﻿using Mbs.Modularity.AddIns;

namespace Mbs.Windows
{
    /// <summary>
    ///  SmartPart Form 视图基类
    /// </summary>
    public class SmartPartForm : FormView, ISmartPartView
    {
        /// <summary>
        /// SmartPart 视图数据
        /// </summary>
        public ISmartPartInfo SmartPartInfo { get; set; }

        /// <summary>
        /// Workspace 名称
        /// </summary>
        public string WorkspaceName { get; set; }

        /// <summary>
        /// 显示SmartPart
        /// </summary>
        public virtual void ShowSmartPart()
        {
            var workspace = Workspace.Get(WorkspaceName);
            if (workspace != null)
            {
                if (SmartPartInfo != null)
                    workspace.Show(this, SmartPartInfo);
                else
                    workspace.Show(this);
            }

        }


        /// <summary>
        /// 插件项配置信息
        /// </summary>
        protected IAddInItem AddInItem { get; private set; }

        /// <summary>
        /// 从配置文件中加载数据
        /// </summary>
        /// <param name="node"></param>
        public new void Load(IAddInItem node)
        {
            AddInItem = node;
            LoadFromAddInItem();
        }

        /// <summary>
        /// 从配置文件中加载数据
        /// </summary>
        protected virtual void LoadFromAddInItem()
        {
        }

        /// <summary>
        /// 刷新国际化资源
        /// </summary>
        public override void RefreshResource()
        {
            base.RefreshResource();
            if (IsSupportGlobalization)
                LoadFromAddInItem();
        }
    }
}
